using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Media;

namespace RevitCopilot.Converters
{
    public class BoolToColorConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value is bool isTrue)
            {
                if (parameter is string colorParams)
                {
                    var colors = colorParams.Split(';');
                    if (colors.Length >= 2)
                    {
                        string colorStr = isTrue ? colors[0] : colors[1];
                        return new BrushConverter().ConvertFrom(colorStr) ?? Brushes.Gray;
                    }
                }

                return isTrue ? Brushes.Green : Brushes.Red;
            }

            return Brushes.Gray;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}